---
category: String
created: '2020-04-19'
title: Get the file name from a URL
updated: '2021-10-13'
---

**JavaScript version**

```js fileName.js
const fileName = (url: string): string => url.substring(url.lastIndexOf('/') + 1);
```

**TypeScript version**

```ts fileName.ts
const fileName = (url: string): string => url.substring(url.lastIndexOf('/') + 1);
```

**Examples**

```js examples.js
fileName('http://domain.com/path/to/document.pdf'); // 'document.pdf'
```
